package com.example.androidkotlinmvvm

import android.content.Intent
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContent {
            Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
                Column(modifier = Modifier.padding(innerPadding)) {
                    baseLayout()
                    listLayout()
                    gridLayout()
                    dataLayout()
                    xmlLayout()
                }
            }
        }
    }

    @Composable
    fun baseLayout(){
        Text(text = "基础布局",
            fontSize = 16.sp,
            fontWeight = FontWeight.Normal,
            modifier = Modifier
                .padding(top = 20.dp, start = 10.dp, bottom = 20.dp)
                .clickable {
                    startActivity(Intent(this, BaseLayoutActivity::class.java))
                })
    }

    @Composable
    fun listLayout(){
        Text(text = "列表布局",
            fontSize = 16.sp,
            fontWeight = FontWeight.Normal,
            modifier = Modifier
                .padding(top = 20.dp, start = 10.dp, bottom = 20.dp)
                .clickable {
                    startActivity(Intent(this, ListActivity::class.java))
                })
    }

    @Composable
    fun gridLayout(){
        Text(text = "网格布局",
            fontSize = 16.sp,
            fontWeight = FontWeight.Normal,
            modifier = Modifier
                .padding(top = 20.dp, start = 10.dp, bottom = 20.dp)
                .clickable {
                    startActivity(Intent(this, GridActivity::class.java))
                })
    }

    @Composable
    fun dataLayout(){
        Text(text = "数据交互",
            fontSize = 16.sp,
            fontWeight = FontWeight.Normal,
            modifier = Modifier
                .padding(top = 20.dp, start = 10.dp, bottom = 20.dp)
                .clickable {
                    startActivity(Intent(this, DataActivity::class.java))
                })
    }

    @Composable
    fun xmlLayout(){
        Text(text = "xml布局交互",
            fontSize = 16.sp,
            fontWeight = FontWeight.Normal,
            modifier = Modifier
                .padding(top = 20.dp, start = 10.dp, bottom = 20.dp)
                .clickable {
                    startActivity(Intent(this, XmlTestActivity::class.java))
                })
    }
}


@Composable
fun Greeting(name: String) {
    Text(
        text = "Hello $name!"
    )
}

@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
        Greeting("Android")
}